package com.iheima.reggie_take.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Email
 * Package: com.iheima.reggie_take.util
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-19
 * Time: 18:11
 */

public class Email {

    public static void SendEmail(String qq,String code) {
        SimpleEmail email = new SimpleEmail();
        //qq：qq邮件服务器的端口号 每个电脑都有一个IP地址
        email.setSslSmtpPort("465");
        //qq邮件的主机 固定的写法
        email.setHostName("smtp.qq.com");
        email.setAuthentication("2295514184@qq.com", "vkjmzusdfmjuebae");
        email.setCharset("UTF-8");
        //1、从文件把所有的qq邮箱读取出来
        //2、存储到一个数据结构当中
        //3、String email = 数据结构当中取一个
        try {
            //email.addTo("1678749516@qq.com");
            email.addTo( qq + "@qq.com");
            email.setFrom("2295514184@qq.com"); //从哪里发
            email.setSubject("龙门客栈登录验证码"); // 邮箱标题
            email.setMsg("验证码为: " +code + "," + "10分钟之内有效!"); //邮箱内容
            email.send();
            System.out.println("发送成功");
        } catch (EmailException e) {
            e.printStackTrace();
        }
    }
}
